#include "ImageData.h"

CImageData::CImageData(KeyPointVector _keys, const char* ImageName, UINT index, double _focal) : m_keys(_keys), m_ImageName(ImageName), m_index(index), m_Focal(_focal)
{
	VISIO_ASSERT(!m_ImageName.empty());
	//load the image
	m_Image = cv::imread(m_ImageName.c_str());
	m_bTracksLoaded = false;
	m_bKeysLoaded = true;
}

void CImageData::SetVisablePoint( CTrackData* pTrack, UINT KeyPointIndex )
{
	VisablePoint visPoint(pTrack, KeyPointIndex);

	m_VisablePoints.push_back(visPoint);
}

UINT CImageData::GetNumVisablePoints() const
{
	return m_VisablePoints.size();
}

VisablePointItr CImageData::VisablePointsBegin()
{
	return m_VisablePoints.begin();
}

VisablePointItr CImageData::VisablePointsEnd()
{
	return m_VisablePoints.end();
}

VisablePointItr CImageData::FindVisablePoint(VisablePointItr ItrToFind)
{
	for (VisablePointItr it = VisablePointsBegin(); it != VisablePointsEnd(); it++)
	{
		//same track
		if (ItrToFind->first == it->first)
		{
			return it;
		}
	}

	//if we didn't find were going to the end
	return VisablePointsEnd();
}

UINT CImageData::GetImageIndex() const
{
	return m_index;
}

cvImage CImageData::GetImage() const
{
	return m_Image;
}

cv::Point2d CImageData::GetKeyPoint( UINT index ) const
{
	return m_keys[index].KeyPoint;
}

double CImageData::GetFocal() const
{
	return m_Focal;
}

void CImageData::MarkKeyPoint( UINT KeyPointIndex, int mark )
{
	m_keys[KeyPointIndex].Mark = mark;
}

int CImageData::GetMark( UINT KeyPointIndex ) const
{
	return m_keys[KeyPointIndex].Mark;
}

void CImageData::RemoveMark( UINT KeyPointIndex )
{
	m_keys[KeyPointIndex].Mark = -2;
}

UINT CImageData::GetNumKeyPoints() const
{
	return m_keys.size();
}

bool CImageData::IsKeyPointMarked( UINT KeyPointIndex ) const
{
	return (GetMark(KeyPointIndex) >= 0);
}

std::string CImageData::GetName() const
{
	return m_ImageName;
}

KeyColor CImageData::GetKeyPointColor( UINT index ) const
{
	return m_keys[index].color;
}
